<style>
    .layui-table-cell .layui-table-sort {
        display: none;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">客户名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerName" id="customerName" class="layui-input"
                                               type="text"
                                               placeholder="请输入客户名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <!-- 客户名称 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">采购组织：</label>
                                    <div class="layui-input-inline">
                                        <input name="purchaseName" id="purchaseName" class="layui-input"
                                               type="text"
                                               placeholder="请输入采购组织" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">提货订单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="orderNo" id="orderNo" class="layui-input"
                                               type="text"
                                               placeholder="请输入提货订单编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">客户下单时间：</label>
                                    <div class="layui-input-inline">
                                        <input id="payStartTimed" class="layui-input date-icon" type="text"
                                               placeholder="请选择客户下单时间"
                                               autocomplete="off" readonly/>
                                        <input name="startTime" id="startTime" style="display: none"/>
                                        <input name="endTime" id="endTime" style="display: none"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="productOrderAdd" type="button" class="layui-btn icon-btn color-reseda">
                                    添加提货订单
                                </button>
                            </div>
                            <div class="lay-btn-rt">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="proDeliveryOrderTableInfo" lay-filter="proDeliveryOrderTableInfo"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="proQualityTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var config = layui.config;
        var admin = layui.admin;

        //时间范围
        laydate.render({
            elem: '#payStartTimed',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    var dateValue = value.split(" - ");
                    $("input[name='startTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endTime']").val(dateValue[1] + " 23:59:59");
                } else {
                    $("input[name='startTime']").val("");
                    $("input[name='endTime']").val("");
                }
            }
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#proDeliveryOrderTableInfo',
            url: config.base + 'production/delivery/admin/orderInfo/list',
            page: true,
            toolbar: true,
            defaultToolbar: ["filter"],
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', align: 'center'}
                , {field: 'recordNo', title: '提货编号', align: 'center', width: 150}
                , {field: 'orderNo', title: '订单编号', align: 'center', width: 150}
                , {field: 'orderSourceName', title: '订单来源', align: 'center'}
                , {field: 'orderTypeName', title: '订单类型', align: 'center'}
                , {field: 'skuCount', title: '物料数', align: 'center', width: 100}
                , {field: 'customerName', align: 'center', title: '所属客户'}
                , {field: 'purchaseCode', title: '采购客户', align: 'center'}
                , {field: 'purchaseName', title: '采购组织', align: 'center'}
                , {field: 'orderTime', title: '下单时间', align: 'center', width: 160}
                , {field: 'createTime', title: '添加时间', align: 'center', width: 160}
                // , {field: 'quantity', title: '发货物流', align: 'center'}
                , {align: 'center', toolbar: '#proQualityTableBar', title: '操作', width: 150}
            ]]
        });

        //渲染下拉
        form.render('select');

        // 工具条点击事件
        table.on('tool(proDeliveryOrderTableInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                productOrderAdd(data);
            } else if (obj.event === 'detail') { //详情
                showDetailModel(data);
            } else if (obj.event === 'closeAndEnd') { //关闭
                closeAndEnd(data);
            } else if (obj.event === 'print') { //产品规划
                console.log("打印...");
            }
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            data.field.givenStartTimed = $("#givenStartTimed").val();
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#productOrderAdd').click(function () {
            productOrderAdd();
        });

        function showDetailModel(data){
            admin.putTempData("productOrderDetailInfoData", data);
            admin.formOpen({
                type: 1,
                area: ['84%', '85%'],
                style: 'font-size: 20px;',
                title: "详情",
                path: "components/product/delivery/orderInfoDetail.html",
                done: function () {
                    // table.reload(insTb, {});
                    insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                }
            });
        }

        function productOrderAdd(data) {
            let title;
            let path;
            if (data) {
                title = "修改提货订单";
                admin.putTempData("productOrderInfoData", data);
                path = "components/product/delivery/orderInfoUpdate.html"
            } else {
                title = "添加提货订单";
                path = "components/product/delivery/orderInfoAdd.html"
            }

            admin.formOpen({
                type: 1,
                area: '1000px',
                offset: '120px',
                style: 'font-size: 20px;',
                title: title,
                path: path,
                done: function () {
                    // table.reload(insTb, {});
                    insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                }
            });
        }
    });
</script>